﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LoLScrape
{
    /// <summary>
    /// Riot Archive File Structure
    /// </summary>
    namespace Archive
    {
        /// <summary>
        ///  Header that appears at start of the archive index file
        /// </summary>
        struct ArchiveHeader
        {
            // Magic value used to identify the file type, must be 0x18BE0EF0
            UInt32 intMagic;

            // Version of the archive format, must be 1
            UInt32 intVersion;

            // An index that is used by the runtime, do not modify
            UInt32 intMgrIndex;

            // Offset to the file list from the beginning of the file
            UInt32 intFileListOffset;

            // Offset to the string table from the beginning of the file
            UInt32 intStringTableOffset;
        } //end ArchiveHeader

        /// <summary>
        ///  Header of the file list
        /// </summary>
        struct FileListHeader
        {
            // Number of entries in the list
            UInt32 intNumFiles;
        } //end FileListHeader

        /// <summary>
        /// An entry in the file list describes a file that has been archived
        /// </summary>
        struct FileListEntry
        {
            // Hash of the string name
            UInt32 intFileNameHash;

            // Offset to the start of the archived file in the data file
            UInt32 intFileOffset;

            // Size of this archived file
            UInt32 intFileSize;

            // Index of the name of the archived file in the string table
            UInt32 intFileNameStringTableIndex;
        } //end FileListEntry

        /// <summary>
        ///  First structure in the built string table
        /// </summary>
        struct StringTableHeader
        {
            // size of all string data including header
            UInt16 intTableSize;

            // Number of strings in the table
            UInt16 intNumStrings;
        } //end StringTableHeader

        /// <summary>
        ///  Entry in the table of contents
        /// </summary>
        struct StringTableEntry
        {
            // Offset from START OF THE STRING TABLE 
            // (i.e. offset from the start of the header structure)
            UInt16 intOffset;

            // Size of string including null
            UInt16 intStringLength;
        } //end StringTableEntry

//        /// <summary>
//        /// Case insensitive hash function used for fast lookup of file names
//        /// </summary>
//        UInt32 HashString(String strName)
//        {
//            UInt32 hash = 0;
//            UInt32 temp = 0;
//
//            foreach (char chr in strName.ToLower())
//            {
//                hash = (hash << 4) + chr;
//                if (0 != (temp = hash & 0xf0000000))
//                {
//                    hash = hash ^ (temp >> 24);
//                    hash = hash ^ temp;
//                } //end if
//            } //end foreach
//
//            return hash;
//        } //end HashString

    } //end Archive
} //end LolScrape
